<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ page import="wtc.stu.entity.StuEntity" %>
<%@ page import="wtc.stu.dao.StuDaoScore" %><%--
  Created by IntelliJ IDEA.
  User: 马可
  Date: 2022/10/30
  Time: 16:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>成绩信息处理</title>
</head>
<body>
<%
    try {
%>
<%
    try {
%>
<%--增加成绩信息功能--%>
<%
    //从form表单获取数据
    String scoreRemark = new String(request.getParameter("scoreRemark").getBytes("ISO8859_1"), StandardCharsets.UTF_8);
    int sid = Integer.parseInt(request.getParameter("sid"));
    int scoreId = Integer.parseInt(request.getParameter("scoreId"));
    int score = Integer.parseInt(request.getParameter("score"));
    // 使用set方法将获取到的数据进行存储并封装
    StuEntity scoreAdd = new StuEntity();
    scoreAdd.setScore(score);
    scoreAdd.setScoreId(scoreId);
    scoreAdd.setSid(sid);
    scoreAdd.setScoreRemark(scoreRemark);
    // 调用相应类的addStu方法将封装好的数据作为参数发送到数据库
    StuDaoScore daoScore = new StuDaoScore();
    daoScore.addStu(scoreAdd);
%>
<%--增加成功提示信息--%>
<script type="text/javascript">
    alert("增加成功！");
    // 跳转到指定页面
    window.location.href = "score.jsp";
</script>
<%
} catch (Exception e) {
%>
<%--修改成绩信息功能--%>
<%
    //从form表单获取数据
    String newScoreRemark = new String(request.getParameter("newScoreRemark").getBytes("ISO8859_1"), StandardCharsets.UTF_8);
    int newScoreId = Integer.parseInt(request.getParameter("newScoreId"));
    int newSid = Integer.parseInt(request.getParameter("newSid"));
    int newScore = Integer.parseInt(request.getParameter("newScore"));
    // 使用set方法将获取到的数据进行存储并封装
    StuEntity stuUpdate = new StuEntity();
    stuUpdate.setScoreId(newScoreId);
    stuUpdate.setScore(newScore);
    stuUpdate.setSid(newSid);
    stuUpdate.setScoreRemark(newScoreRemark);
    // 调用相应类的addStu方法将封装好的数据作为参数发送到数据库
    StuDaoScore daoScoreUpdate = new StuDaoScore();
    daoScoreUpdate.updateStu(stuUpdate);
%>
<%--增加成功提示信息--%>
<script type="text/javascript">
    alert("修改成功！");
    // 跳转到指定页面
    window.location.href = "score.jsp";
</script>
<%
    }
%>
<%
} catch (Exception e) {
%>
<%--删除成绩信息功能--%>
<%
    //从form表单获取数据
    int delScoreId = Integer.parseInt(request.getParameter("delScoreId"));
    // 调用相应类的方法，并将获取到的数据作为参数
    StuDaoScore daoScoreDel = new StuDaoScore();
    daoScoreDel.delStu(delScoreId);
    // 再次通过form表单获取到的数据调用相应类的getOneById方法进行查询，用返回值来进行判断
    StuEntity pd = daoScoreDel.getOneById(delScoreId);
    int c = pd.getScoreId();
    if (c == 0) {
%>
<%--删除成功提示信息--%>
<script type="text/javascript">
    alert("删除成功！");
    // 跳转到指定页面
    window.location.href = "score.jsp";
</script>
<%
} else {
%>
<%--删除失败提示信息--%>
<script type="text/javascript">
    alert("删除失败！存在外键关联或其他原因！");
    // 跳转到指定页面
    window.location.href = "score.jsp";
</script>
<%
    }
%>
<%
    }
%>
</body>
</html>
